﻿using System.Globalization;
using System.Text;

namespace System;

/// <summary>
/// 字段串扩展
/// </summary>
public static class AppStringExtensions
{
    /// <summary>
    /// 短横线分隔命名 转换为 驼峰命名法
    /// </summary>
    /// <param name="str">原始字段串</param>
    /// <returns></returns>
    public static string KebabCaseToCamelCase(this string str)
    {
        if (string.IsNullOrWhiteSpace(str))
        {
            return str;
        }

        if (!str.Contains('-'))
            return str;
        var strings = str.Split('-', StringSplitOptions.RemoveEmptyEntries);
        var sb = new StringBuilder();
        var textInfo = CultureInfo.CurrentCulture.TextInfo;

        for (var i = 0; i < strings.Length; i++)
        {
            sb.Append(i == 0 ? strings[i] : textInfo.ToTitleCase(strings[i]));
        }

        return sb.ToString();
    }
}